/** <a href="http://www.cpupk.com/decompiler">Eclipse Class Decompiler</a> plugin, Copyright (c) 2017 Chen Chao. **/
package com.minierp.controller;

import com.minierp.bean.ClieUserBean;
import com.minierp.dao.ClieUserDao;
import com.minierp.helper.EncCommonHelper;
import com.minierp.model.ClieUser;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;

public class ClieAccoFormCtr extends SimpleFormController {
	private ClieUserDao clieUserDao;

	public ClieUserDao getClieUserDao() {
		return this.clieUserDao;
	}

	public void setClieUserDao(ClieUserDao clieUserDao) {
		this.clieUserDao = clieUserDao;
	}

	protected Object formBackingObject(HttpServletRequest request)
			throws Exception {
		ClieUserBean form = new ClieUserBean();
		ClieUserBean ub = EncCommonHelper.getClieUserAccount(request);
		ClieUser u = (ClieUser) this.clieUserDao.get(ClieUser.class, ub
				.getUser().getId());
		form.setUser(u);
		form.setClieName(ub.getClie().getEstName());
		return form;
	}

	protected void onBind(HttpServletRequest request, Object command)
			throws Exception {
	}

	protected ModelAndView onSubmit(HttpServletRequest request,
			HttpServletResponse response, Object command, BindException errors)
			throws Exception {
		ClieUserBean ub = EncCommonHelper.getClieUserAccount(request);
		ClieUserBean form = (ClieUserBean) command;
		ClieUser u = form.getUser();
		if (u.getPassword() == null || u.getPassword().equals("")) {
			u.setPassword(form.getCurrentPassword());
		}

		this.clieUserDao.update(u);
		ub.getUser().setPassword(u.getPassword());
		ub.getUser().setUserName(u.getUserName());
		EncCommonHelper.setClieUserAccount(request, ub);
		ModelAndView mv = new ModelAndView("redirect:/online/AccoEdit.ihtm");
		EncCommonHelper.setAlertMessage(request, "修改成功！");
		return mv;
	}
}